package kite.sso.util;

import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.io.InputStream;

/**
 * 功能描述: <br>
 * 所属包名: kite.sso.util<br>
 * 创建人　: 白剑<br>
 * 创建时间: 06/12/2018 12:35 Tuesday<br>
 * 当前版本: 1.0<br>
 * 修改历史: <br>
 * 修改时间　　　　　修改人　　　　　版本变更　　　　　修改说明<br>
 * -----------------------------------------------------<br>
 * <br>
 */
public class HttpResponseUtil {

    public static JSONObject getResponseData(InputStream responseStream) throws IOException {

        byte[] temp = new byte[1024];
        StringBuilder sb = new StringBuilder();
        int len = 0;

        try {
            while ((len = responseStream.read(temp)) > 0) {
                sb.append(new String(temp, 0, len));
            }
        } finally {
            if (null != responseStream) {
                responseStream.close();
            }
        }

        return null != sb ? JSONObject.parseObject(sb.toString()) : null;
    }
}
